#include "setwig.h"
#include "ui_setwig.h"

SetWig::SetWig(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SetWig)
{
    ui->setupUi(this);
    //连接断开按钮的设计
//   readConfigtable();
   connect(ui->pushButton_conn,SIGNAL(clicked()),this,SLOT(btnConnClickedSlot()));
   connect(ui->pushButton_set_1,SIGNAL(clicked()),this,SLOT(setBtn1()));
   connect(ui->pushButton_set_2,SIGNAL(clicked()),this,SLOT(setBtn2()));
   connect(ui->pushButton_set_3,SIGNAL(clicked()),this,SLOT(setBtn3()));



}


SetWig::~SetWig()
{
    delete ui;
}

void SetWig::btnConnClickedSlot()
{

    QString mqttip;
    mqttip=QString(ui->lineEdit_ip->text());
    if(mqttip=="")
    {
        QMessageBox::warning(this,"提示","ip地址不能为空！");
        return;
    }
    emit mySignal(mqttip);
    ui->pushButton_discon->setEnabled(true);
    ui->pushButton_conn->setEnabled(false);
    ui->pushButton_conn->setText("已连接");
    connect(ui->pushButton_discon,SIGNAL(clicked()),this,SLOT(disconnectBtnSlot()));
}

void SetWig::disconnectBtnSlot()
{
    ui->lineEdit_ip->clear();
    ui->pushButton_discon->setEnabled(false);
    ui->pushButton_conn->setText("连接");
    ui->pushButton_conn->setEnabled(true);
}

void SetWig::huixianshuju(QString buf)
{

    if(buf=="Modified successfully")
    {
        QMessageBox::information(this,"information","Modified successfully");
    }
    else if(buf=="Modified failed")
    {
        QMessageBox::warning(this,"warning","Modified failed");
    }
}

void SetWig::setBtn1()
{
    int flag=0;
    emit sbmode1(flag);
}

void SetWig::setBtn2()
{
    int flag=1;
    emit sbmode2(flag);
}

void SetWig::setBtn3()
{
    int flag=2;
    QString zq=ui->lineEdit_zqsb->text();
    if(zq=="")
    {
        QMessageBox::information(this,"information","周期不能为空！");
    }
    else if(zq!="")
    {
    int value=zq.toInt();
    emit sbmode3(flag,value);
    }
}



